<template>
  <div class="">
    <div class="list" v-for="(item, index) in tapList" :key="index">
      <img :src="item.author.avatar_url" alt="" />
      <div>
        <p>{{ item.title }}</p>
        <p class="time">{{ item.create_at | diaplayTime }}</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["tapList"],
  data() {
    return {};
  },
  mounted() {},
  methods: {},
  filters: {
    diaplayTime(data) {
      //将字符串转换成时间格式
      let result;
      let timePublish = new Date(data);
      let timeNow = new Date();
      let minute = 1000 * 60;
      let hour = minute * 60;
      let day = hour * 24;
      let month = day * 30;
      let year = month * 12;
      let diffValue = timeNow - timePublish;
      let diffMonth = diffValue / month;
      let diffWeek = diffValue / (7 * day);
      let diffDay = diffValue / day;
      let diffHour = diffValue / hour;
      let diffMinute = diffValue / minute;
      let diffYear = diffValue / year;
      if (diffValue < minute) {
        result = "刚刚发表";
      } else if (diffYear > 1) {
        result = parseInt(diffYear) + "年前";
      } else if (diffMonth > 1) {
        result = parseInt(diffMonth) + "月前";
      } else if (diffWeek > 1) {
        result = parseInt(diffWeek) + "周前";
      } else if (diffDay > 1) {
        result = parseInt(diffDay) + "天前";
      } else if (diffHour > 1) {
        result = parseInt(diffHour) + "小时前";
      } else if (diffMinute > 1) {
        result = parseInt(diffMinute) + "分钟前";
      } else {
        result = "刚刚发表";
      }
      return result;
    },
  },
  components: {},
};
</script>

<style lang="scss" scoped>
.list {
  width: 100%;
  height: 4.5rem;
  display: flex;
  background-color: #fff;
  font-size: 0.5rem;
  img {
    width: 4.5rem;
    height: 100%;
  }
  .time {
    width: 60px;
    padding: 5px;
    background-color: rgb(76, 198, 247);
  }
}
</style>
